package com.coffeeloversupportlibrary.core.base;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.room.RoomDatabase;
import com.coffeeloversupportlibrary.core.data.IDataRepository;

/**
 * @author puyv
 * @createTime 2021/11/3 14:48
 * @projectName CoffeeLoverSupportLibrary
 * @className BaseModel.java
 * @description TODO
 */
public class BaseModel implements IModel{

    private IDataRepository mDataRepository;

    public BaseModel(IDataRepository dataRepository){
        this.mDataRepository = dataRepository;
    }

    /**
    * @date 2021/11/4 9:09
    * @params []
    * @return
    * @description 生命周期销毁的时候，释放仓库的链接
    */
    @Override
    public void onDestroy() {
        mDataRepository = null;
    }

    /**
    * @date 2021/11/4 8:52
    * @params [service]
    * @return T
    * @description 返回 APIService 接口的动态代理
    */
    public <T> T getRetrofitService(Class<T> service){
        return mDataRepository.getRetrofitService(service);
    }


    /**
    * @date 2021/11/4 9:07
    * @params [database, dbName, context]
    * @return T
    * @description 获取数据库
    */
    public <T extends RoomDatabase> T getRoomDatabase(@NonNull Class<T> database, @NonNull String dbName,@NonNull Context context){
        return mDataRepository.getRoomDatabase(database,dbName,context);
    }

}
